// pages/bind/bind.js
import Config from "../../common/config.js";
Page({

  /**
   * 页面的初始数据
   */
  data: {
      bindList:{},
      bookid:"",
      bindIndex:0,
      bindingId:""

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    console.log(options)
    that.setData({
      bookid: options.bookid,

    })
    var sessionId = wx.getStorageSync('sessionId')
  
    wx.request({
      url: Config.url + '/api/makeBook/selectBind',
      method: 'POST',
      header: {
        'content-type': 'application/json',
        'cookie': sessionId
      },
      success(res) {
        console.log(res)
        that.setData({
          bindList: res.data.data.data,
          bindingId: res.data.data.data[0].bindingId
        })
        var arrays = res.data.data.data

       
      }
    })
  },
  choseBind: function (e) {
    
    this.setData({
      bindIndex: e.currentTarget.dataset.index,
      bindingId: e.currentTarget.id
    })
    

  },
  begin: function () {
    var that = this
    var sessionId = wx.getStorageSync('sessionId')
    wx.request({
      url: Config.url + '/api/book/save',
      method: 'POST',
      header: {
        'content-type': 'application/json',
        'cookie': sessionId
      },
      data: { bindingId: that.data.bindingId, bookId: that.data.bookid },
      success(res) {
        wx.navigateTo({
          url: '../book/book?bookId=' + that.data.bookid
        })

      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },


})